<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>AopPreventingRepeatSubmissionsApplication</title>
</head>
<body>
<form id="myForm" action="http://127.0.0.1:8080/submit" method="POST">
    <label for="name">姓名:</label><br>
    <input type="text" id="name" name="name"><br>
    <label for="age">年龄:</label><br>
    <input type="text" id="age" name="age"><br><br>
    <button type="submit">提交</button>
</form>

<script>
    document.getElementById("myForm").addEventListener("submit", function(event) {
        event.preventDefault();  // 阻止默认的表单提交行为

        var form = event.target;
        var formData = new FormData(form);

        fetch(form.action, {
            method: 'POST',
            body: formData
        }).then(response => {
            if (response.ok) {
                console.log('提交成功');
                // 可以在此处理成功后的逻辑，比如显示成功信息或者重定向页面
            } else {
                console.error('提交失败');
            }
        }).catch(error => {
            console.error('网络错误:', error);
        });
    });
</script>

</body>
</html>
